#define _CRT_SECURE_NO_WARNINGS 1

#include"SLT.h"

void InspectPrint(SLTNode *plist)
{
	printf("inspect SListPrint:\n");
	SListPrint(plist);
	printf("--------------------------------------------------------------------------------------------\n");
}

void InspectPushBack(SLTNode** pplist)
{
	printf("Inspect SListPushBack:\n");
	SListPushBack(pplist, 5);
	SListPrint(*pplist);
	printf("\n");
	printf("the situation that the pointer of the Single Linked List is NULL:\n");
	SLTNode* plist2 = NULL;
	SListPushBack(&plist2, 0);
	SListPushBack(&plist2, 1);
	SListPushBack(&plist2, 2);
	SListPushBack(&plist2, 3);
	SListPushBack(&plist2, 4);
	SListPrint(plist2);
	printf("--------------------------------------------------------------------------------------------\n");
}

void InspectPushFront(SLTNode** pplist)
{
	printf("Inspect SListPushFront:\n");
	SListPushFront(pplist, -1);
	SListPrint(*pplist);
	printf("--------------------------------------------------------------------------------------------\n");
}

void InspectPopBack(SLTNode** pplist)
{
	printf("Inspect SListPopBack\n");
	SListPopBack1(pplist);
	SListPrint(*pplist);
	printf("\n");
	printf("the other way:\n");
	SListPopBack2(pplist);
	SListPrint(*pplist);
	printf("--------------------------------------------------------------------------------------------\n");
}

void InspectPopFront(SLTNode** pplist)
{
	printf("Inspect SListPopFront:\n");
	SListPopFront(pplist);
	SListPrint(*pplist);
	printf("\n");
	printf("--------------------------------------------------------------------------------------------\n");
}

void InspectSearch(SLTNode** pplist)
{
	printf("add content of linked list\n");
	SListPushBack(pplist, 4);
	SListPushBack(pplist, 5);
	SListPushBack(pplist, 6);
	SListPushBack(pplist, 7);
	SListPushBack(pplist, 8);
	SListPushBack(pplist, 9);
	SListPushBack(pplist, 10);
	SListPrint(*pplist);
	printf("Inspeact SListSearch:\n");
	SLTNode *ret = SListSearch(*pplist, 8);
	printf("%d\n", *ret);
	printf("--------------------------------------------------------------------------------------------\n");
}

void InspectInsertAfter(SLTNode** pplist)
{
	printf("Inspect SListInsertAfter:\n");
	SListInsertAfter1(*pplist, 12);
	SListPrint(*pplist);
	SListInsertAfter2(*pplist, 11);
	SListPrint(*pplist);
	printf("--------------------------------------------------------------------------------------------\n");
}

void InspectEraseAfter(SLTNode** pplist)
{
	printf("Inspect SListEraseAfter:\n");
	SListEraseAfter(*pplist);
	SListEraseAfter(*pplist);
	SListPrint(*pplist);
	printf("--------------------------------------------------------------------------------------------\n");
}

void InspectDestroy(SLTNode** pplist)
{
	printf("Inspect SListDestroy:\n");
	SListDestroy(pplist);
	SListPrint(*pplist);
}

int main()
{
	SLTNode* s1 = (SLTNode*)malloc(sizeof(SLTNode));
	assert(s1);
	SLTNode* s2 = (SLTNode*)malloc(sizeof(SLTNode));
	assert(s2);
	SLTNode* s3 = (SLTNode*)malloc(sizeof(SLTNode));
	assert(s3);
	SLTNode* s4 = (SLTNode*)malloc(sizeof(SLTNode));
	assert(s4);
	s1->data = 1;
	s2->data = 2;
	s3->data = 3;
	s4->data = 4;
	s1->next = s2;
	s2->next = s3;
	s3->next = s4;
	s4->next = NULL;
	InspectPrint(s1);
	InspectPushBack(&s1);
	InspectPushFront(&s1);
	InspectPopBack(&s1);
	InspectPopFront(&s1);
	InspectSearch(&s1);
	InspectInsertAfter(&s1);
	InspectEraseAfter(&s1);
	InspectDestroy(&s1);
	return 0;
}

//void Swap(int* nums, int left, int right) {
//    while (left < right)
//    {
//        int temp = nums[left];
//        nums[left] = nums[right];
//        nums[right] = temp;
//        left++;
//        right--;
//    }
//}
//
//
//void rotate(int* nums, int numsSize, int k) {
//    k %= numsSize;
//    Swap(nums, 0, numsSize - 1);
//    Swap(nums, 0, k - 1);
//    Swap(nums, k, numsSize - 1);
//}
